package com.example.chao.myphotosearch.adapters.holders;

import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;

import com.example.chao.myphotosearch.R;
import com.example.chao.myphotosearch.bean.SosoImage;
import com.facebook.drawee.view.SimpleDraweeView;
import com.jude.utils.JUtils;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by chao on 2016/4/7.
 */
public class SearchHolder extends BaseViewHolder<SosoImage> {
    @Bind(R.id.item_search_SDV)
    SimpleDraweeView itemSearchSDV;
    private float width;
    private float height;
    private float screenWidth;
    private ViewGroup.LayoutParams layoutParams;
    public SearchHolder(ViewGroup parent) {
        super(parent, R.layout.item_search);
        ButterKnife.bind(this, itemView);

    }

    @Override
    public void setData(SosoImage data) {
        screenWidth = JUtils.getScreenWidth()/2;
        height =data.getHeight();
        width = data.getWidth();
        if(!TextUtils.isEmpty(data.getThumbImg())){
            layoutParams= itemSearchSDV.getLayoutParams();
            layoutParams.height= (int)((height/width)*screenWidth);
            itemSearchSDV.setLayoutParams(layoutParams);
        }
        itemSearchSDV.setImageURI(Uri.parse(data.getThumbImg()));

    }
}
